//******************************************************************************
//this code is protected by the GNU affero GPLv3
//author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com>
//                        <digital.ragnarok AT gmail dot com>
//******************************************************************************
#include "globals.h"

#define EV_DONE_DWS 3
s8 wl_callback_ev_done(struct client *c,u32 id,u32 serial)
{
  u32 ev[EV_DONE_DWS];

  ev[0]=id;
  u16 ev_sz=EV_DONE_DWS*sizeof(u32);
  ev[1]=ev_sz<<16|WL_CALLBACK_DONE;
  ev[2]=serial;

  struct io_vec iov;
  iov.base=&ev;
  iov.len=ev_sz;

  struct msg_hdr msg;
  memset(&msg,0,sizeof(msg));
  msg.iov=&iov;
  msg.iov_len=1;

  LOG_WIRE("client(%d):callback::done callback_id=%u serial=%u\n",c->so,
                                                               id,serial,ev_sz);
  l r;
  while(1){r=sendmsg(c->so,&msg,0); if(r!=-EINTR) break;}

  if(ISERR(r)){
    PERR("client(%d):fatal(%ld):callback::done unable to send event"
                               " callback_id=%u serial=%u\n",c->so,r,id,serial);
    r=LWL_ERR;goto exit;
  }
  if(r!=ev_sz){
    PERR("client(%d):fatal:callback::done only %ld/%ld was sent\n",c->so,
                                                                       r,ev_sz);
    r=LWL_ERR;goto exit;
  }

exit:
  return (s8)r;
}
